<?php
if (!defined('W_ROOT')) {
	exit();
}
$_SESSION['shop_return_url'] = $_SERVER['REQUEST_URI'];
?>
<div class="breadcrumb">
		<a href="<?php echo base_url_admin;?>"><?php echo $lang['HOME'];?></a>
		:: <a href=""><?php echo $lang['LIST_USER'];?></a>
		</div>
		<?php
			$messages = isset($_GET['message']) ? $_GET['message']: "";
			if($messages == 'aproved'){
				echo '<div class="success">Message: '.@$_GET['name'].' account has been activated!</div>';
			}
			if($messages == 'invalid'){
				echo '<div class="warning">Message: '.@$_GET['name'].' account can not be activated!</div>';
			}
			if(!empty($_GET['messaget'])){
				echo '<div class="warning">Message: User has been deleted!</div>';
			}
		?>
<div class="heading">
	<h1><img src="../templates/image/user.png" alt="" />
		<?php
			echo $lang["LIST_USER"];
			$myslqstatmet = "SELECT * FROM tbluser WHERE id!='".$_SESSION['acc_id']."'";
			$sqlquery = @mysql_query($myslqstatmet);
			$numberofmember = @mysql_num_rows($sqlquery);
			echo " ( ".@$numberofmember." Members)";
		?>

	</h1>
	<div class="buttons">

	<a href="index.php?view=add" class="button"><?php echo $lang['INSERT'];?></a>
	<a href="javascript:;" class="button" id="OnDelete"><?php echo $lang['DELETE'];?></a></div>
	<div style="display:none; float:right; padding-top:7px;" id="deleteSucess_1"><img src="../images/load.gif" /></div>
	<script type="text/javascript">
	$(document).ready(function(){

		$('#OnDelete').on('click',function(){
			 $('#deleteSucess_1').fadeIn();
			 $('#deleteSucess').hide();
			var checkId = $('.check_box:checked').map(function(){
					return this.value;
				}).get().join(',');
			if(checkId==''){
					alert("<?php echo $lang['MESSAGE_SELECT'];?>");
					$('#deleteSucess_1').fadeOut();
				}
			  $.ajax
              ({
                  type: "GET",
                  url: "check.php",
                  data: {checkId:checkId},
                  cache: false,
                  success: function(html)
                  {
                      if(html){
                          $('#delsucess').html(html);
                          $('#deleteSucess_1').fadeOut();
                      }
					$("#loading").fadeOut(200);
                  }
              });
			});
		});
	</script>
</div>
<SCRIPT language="javascript">
		$(function(){

			// add multiple select / deselect functionality
			$("#chkall").click(function () {
				  $('.check_box').attr('checked', this.checked);
			});

			// if all checkbox are selected, check the selectall checkbox
			// and viceversa
			$(".check_box").click(function(){

				if($(".check_box").length == $(".check_box:checked").length) {
					$("#chkall").attr("checked", "checked");
				} else {
					$("#chkall").removeAttr("checked");
				}

			});
		});
</SCRIPT>
<div class="box">
<div class="content">
	<div>
	<form method="get" action="index.php">
		<span>Filter</span><select name="txtSelectFilter">
			<option value="0">Activated</option>
			<option value="1">Administrator</option>
			<option value="2">Premium-accout</option>
			<option value="3">Free account</option>
			<option value="4">Active</option>
			<option value="5">Inactive</option>
		</select>
		<span><input type="submit" name="action" value="filter"/></span>
		<span><a class = "button" href="<?php echo base_url_admin;?>/user/index.php">View all</a></span>
	</form>
	</div>
	<br/>
 <div id="delsucess"></div>
      <div id="deleteSucess" style="display:none;"><?php echo $lang['MESSAGE_DELETE_SUCCESS'];?></div>
		<table class="list">
			<thead>
				<tr>

					<td width="1"><?php echo $lang['N']; ?></td>
					<td class="left"  ><input type="checkbox" name="chkall[]" id="chkall" onClick="checkAll(this.form,this.checked)" style="cursor:pointer;"></td>
					<td class="left" ><?php echo $lang['USER_NAME'] ;?></td>
					<td class="left" ><?php echo $lang['USERTYPEE'];?></td>
					<td class="left" ><?php echo $lang['Email'];?></td>
					<td class="left"><?php echo $lang['CRETE_DATE'];?></td>
					<td class="left"><?php echo $lang['MODI_DATE'];?></td>
					<td class="left"><?php echo $lang['STATUS'];?></td>
					<td class="left"><?php echo $lang['ACTIVATED'];?></td>
					<td class="center"><?php echo $lang['OTHER']; ?></td>

				</tr>
		</thead>
		<tbody>

		<?php
		 $where = '';
			if(isset($_GET['action'])){
				$Filterby = isset($_GET['txtSelectFilter']) ? $_GET['txtSelectFilter'] : "";
				switch ($Filterby){
					case '0':
						$where = ' WHERE activated_status=0 AND user_type_id=2';
						break;
					case '1':
						$where = ' WHERE  user_type_id=4';
						break;
					case '2':
						$where = ' WHERE  user_type_id=2';
						break;
					case '3':
						$where = ' WHERE  user_type_id=3';
						break;
					case '4':
						$where = ' WHERE  status=1';
						break;
					case '5':
					$where = ' WHERE  status=0';
					break;
				}
			}
		 $where =  ($where)?$where." AND id !='".$_SESSION['acc_id']."'":"WHERE id != ".$_SESSION['acc_id'];
			if(!empty($_GET['view'])& @$_GET['view']=='listadmin'){
				$id = $_GET['id'];
				$where = ' WHERE  id='.$id;
			}

			$page = '';
			$per_page = 10;
			if(isset($_GET['page']))
			{
			$page=$_GET['page'];
			$start = ($page-1)*$per_page;
			}else{
			$start = 0;
			}
			$sql = "SELECT * FROM tbluser ".@$where." ORDER BY cdate DESC limit $start,$per_page";
			$result     = mysql_query($sql);
			$i = 1;
			while($row = mysql_fetch_assoc($result)){
			extract($row);

			if($i%2){
			$class = 'row1';
			}else{
			$class = 'row2';
			}

			$sql_type = "SELECT user_type_name FROM tbluser_type WHERE user_type_id = $user_type_id";
			$result_type = mysql_query($sql_type);
			$row_type = mysql_fetch_assoc($result_type);
			
			$sql_upgrad_account = mysql_query("SELECT *FROM tbl_refcode WHERE ref_type='user_upgrade' AND ref_oject_id='".$row['id']."' LIMIT 1");
			$rows_upgrad_account = mysql_num_rows($sql_upgrad_account);
		?>

		<tr class="<?php echo $class;?>" id="user<?php echo $row[tbluser::id]; ?>">
			<td class="left"><?php echo $i;?></td>
			<td class="left"><input type="checkbox" class="check_box" id="chk" class="check_box" name="id[]" value="<?php echo $row['id'];?>" /></td></td>
			<td class="left">
			<a href="<?php echo base_url_admin;?>/user/index.php?view=views&amp;id=<?php echo $id?>">
			<?php
				if($username!=""){
					echo $username;
				}else{
					echo $first_name.' '.$last_name	;
				}
			?>
		</a>
			</td>
			<td class="left"><a href="<?php echo base_url_admin;?>/user/index.php?view=views&amp;id=<?php echo $id?>"><?php echo $row_type[Tbluser_type::user_type_name]; ?></a></td>
			<td class="left"><a href="<?php echo base_url_admin;?>/user/index.php?view=views&amp;id=<?php echo $id?>"><?php echo $row['email']; ?></a></td>
			<td class="left"><a href="<?php echo base_url_admin;?>/user/index.php?view=views&amp;id=<?php echo $id?>"><?php echo $row[tbluser::cdate]; ?></a></td>
			<td class="left"><a href="<?php echo base_url_admin;?>/user/index.php?view=views&amp;id=<?php echo $id?>"><?php echo $row[tbluser::mdate]; ?></a></td>
			<td class="center">
				<?php
					if($row['activated_status'] == 0 && $row['user_type_id'] == 2){
						echo 'Activate first';
					} else {
						echo stateImage($row[tbluser::id],$row[tbluser::status]);
					}
				 ?>

			 </td>
			<td class="left">
				<?php
					if (1 == $row['user_type_id'] || 4 == $row['user_type_id']) {
						echo '';
					} else {
						if (1 == $row['activated_status']) {
							echo 'Active';
						} elseif(1 != $row['activated_status'] && 3 != $row['user_type_id'] || $rows_upgrad_account > 0) {
							echo '<a class="button"  href="'.base_url_admin.'/user/index.php?view=views&amp;id=' .$id.'">
							Activated
							</a>';
						}
					}
				?>
			</td>
			<td class="center"><a href="<?php echo base_url_admin;?>/user/index.php?view=add&amp;id=<?php echo $id;?>"><img width="20" src="../templates/image/Edit.gif" alt="<?php echo $lang['EDIT'];?>" /></a>
			 <a onclick="return ConfirmDelete('<?php echo base_url_admin;?>/user/process.php?action=delete&amp;id=<?php echo $id;?>')" href="javascript:;"><img width="20" src="../templates/image/trash.png" alt="<?php echo $lang['DELETE'];?>" /></a>
			</td>
		</tr>
		<?php
			$i++;
			}// end while
		?>
		</tbody>
		</table>
		</form>
		<?php
				$pages = '';
				$per_page = 10;
				$select_table = "SELECT * FROM ".Tbluser::Tbluser ;
				$variable = mysql_query($select_table);
				$count = mysql_num_rows($variable);
				$pages = ceil($count/$per_page);

		?>
		<div class="pagination">

		<div class="links">
		<?php
		if($pages!=1){
		for($i=1; $i<=$pages; $i++){
		?>
		<a href="<?php echo base_url_admin;?>/user/index.php?page=<?php echo $i;?>"><b style="background-color:<?php echo ($i==@$_GET['page'])?"#A2CC3A":""; ?>;"><?php echo $i;?></b></a>
		<?php
			}
		}
		?>
		 </div>
			<div class="results">
					<?php
						echo $lang['SHOWING'].'1 to 10 of '.$count." (".@$_GET['page']." Page)";
					?>
			</div>
		</div>
		</div>
		</div>
